/**
 *    Copyright (C) 2008, 2009  Victor Smirnov <aist11@gmail.com>
 *
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License along
 *    with this program; if not, write to the Free Software Foundation, Inc.,
 *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 *    See LICENSE.exceptions in the root folder of this project for possible
 *    exceptions
 *
 */


package ru.teleology.cubefs.api.models;

import ru.teleology.cubefs.api.reflection.NativeType;
import ru.teleology.cubefs.api.reflection.Type;
import ru.teleology.cubefs.api.reflection.TypeSystem;
import ru.teleology.cubefs.api.reflection.Typed;
import ru.teleology.cubefs.api.reflection.Types;

@NativeType(name = Types.ITERATOR_TYPE)
public class Iterator extends Typed {

	public static final int ITER_EOF 		= 0;
	public static final int ITER_EMPTY	= 1;
	public static final int ITER_BOF 		= 2;
	
	private static final Type myType = TypeSystem.find(Types.ITERATOR_TYPE);
	private Operations operations = (Operations) myType.proxy(this);
	
	public Iterator(long handle) {
		super(handle);
	}
	
	public boolean Next() {
		//return operations.Next();
		return Next(getHandle());
	}
	
	public boolean Prev() {
		return operations.Prev();
	}

	public void Close() {
		operations.Close();
	}
	
	public boolean IsClonable() {
		return operations.IsClonable();
	}
	
	public Iterator Clone() {
		return operations.Clone();
	}
	
	public void GetValue(Typed holder) {
		//operations.GetValue(holder);
		GetValue(getHandle(), holder.getHandle());
	}

	public boolean IsFlag(int flag) {
		//return operations.IsFlag(flag);
		return IsFlag(getHandle(), flag);
	}
	
	public boolean IsEof() {
		return IsFlag(ITER_EOF);
	}
	
	public boolean IsBof() {
		return IsFlag(ITER_BOF);
	}
	
	public boolean IsEmpty() {
		return IsFlag(ITER_EMPTY);
	}

    private static native boolean IsFlag(long me, int flag);
    private static native boolean Next(long me);
    private static native void GetValue(long me, long holder);

	public interface Operations {
//            boolean Next();
	    boolean Prev();

	    void Close();
	    boolean IsClonable();
	    Iterator Clone();
//	    void GetValue(Typed holder);

//	    boolean IsFlag(int flag);
	}

        
}
